<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:define name="top">
        Edit #{categoryCTRL.category.name}
    </ui:define>

    <ui:define name="left">
    </ui:define>

    <ui:define name="body">
        <h:form id="newCategoryForm">
            <h:panelGrid columns="4">
                <h:outputLabel for="name" value="Name:"/>
                <h:inputText id="name" value="#{categoryCTRL.category.name}">
                    <f:validator validatorId="validators.generalLengthValidator"/>
                </h:inputText>
                <h:panelGroup/>
                <h:message for="name"/>
                
                
                <h:outputLabel for="descrip" value="Description:"/>
                <h:inputTextarea id="descrip" value="#{categoryCTRL.category.descrip}">
                    <f:validator validatorId="validators.descriptionValidator"/>
                </h:inputTextarea>
                <h:panelGroup/>
                <h:message for="descrip"/>
                
                <h:outputLabel for="catList" value="Sub-Category of:"/>
                <c:choose>
                    <c:when test="#{empty categoryCTRL.category.categoryByCategoryOf}">
                        <h:selectOneMenu id="catList">
                            <f:selectItem itemValue="-1" itemLabel=""/>
                            <c:forEach items="#{categoryCTRL.categoryList}" var="items">
                                <f:selectItem itemValue="#{items.id}" itemLabel="#{items.level}#{items.name}"/>
                            </c:forEach>
                        </h:selectOneMenu>
                    </c:when>
                    <c:otherwise>
                        <h:selectOneMenu id="catList" value="#{categoryCTRL.category.categoryByCategoryOf.id}">
                            <f:selectItem itemValue="-1" itemLabel=""/>
                            <c:forEach items="#{categoryCTRL.categoryList}" var="items">
                                <f:selectItem itemValue="#{items.id}" itemLabel="#{items.name}"/>
                            </c:forEach>
                        </h:selectOneMenu>
                    </c:otherwise>
                </c:choose>
                
                
                <h:panelGroup/>
                <h:panelGroup/>
                
                <h:outputLabel for="catList2" value="Suitable For:"/>
                
                <c:choose>
                    <c:when test="#{empty categoryCTRL.category.categoryBySuitableFor}">
                        <h:selectOneMenu id="catList2">
                            <f:selectItem itemValue="-1" itemLabel=""/>
                            <c:forEach items="#{categoryCTRL.categoryList}" var="items">
                                <f:selectItem  itemValue="#{items.id}" itemLabel="#{items.level}#{items.name}"/>
                            </c:forEach>
                        </h:selectOneMenu>
                    </c:when>
                    <c:otherwise>
                        <h:selectOneMenu id="catList2" value="#{categoryCTRL.category.categoryBySuitableFor.id}">
                            <f:selectItem itemValue="-1" itemLabel=""/>
                            <c:forEach items="#{categoryCTRL.categoryList}" var="items">
                                <f:selectItem  itemValue="#{items.id}" itemLabel="#{items.name}"/>
                            </c:forEach>
                        </h:selectOneMenu>
                    </c:otherwise>
                </c:choose>
                <h:panelGroup/>
                <h:panelGroup/>
                </h:panelGrid>
            <div style=" background-color: gray">Old Attributes</div>
            <h:panelGrid columns="4">
                <c:forEach varStatus="counter" items="#{categoryCTRL.category.attributes}" var="attribute">
                    <h:outputLabel value="#{counter.count})."/>
                    <h:inputText value="#{attribute.name}"/>
                    <h:outputLabel value="Delete?"/>
                    <h:selectBooleanCheckbox label="Delete" value="#{attribute.selected}"/>
                </c:forEach>
             </h:panelGrid>
            <c:if test="#{categoryCTRL.noDefineCategoryAttributes > 0}">
                <div style=" background-color: gray">New Attributes</div>
            </c:if>
            <h:panelGrid rendered="#{categoryCTRL.noDefineCategoryAttributes > 0}" columns="4">
                <c:forEach var="i" begin="1" end="#{categoryCTRL.noDefineCategoryAttributes}">
                    <h:outputLabel value="Name:"/>
                    <h:inputText id="attribute${i}">
                        <f:validator validatorId="validators.generalLengthValidator"/>
                    </h:inputText>
                    <h:panelGroup/>
                    <h:message for="attribute${i}" />
                </c:forEach>
            
               
                
            </h:panelGrid>
            <br/>
            &nbsp;&nbsp;&nbsp;<h:commandButton action="#{categoryCTRL.updateCategory}" value="Submit"/>
        </h:form>
        <h:form>
            <h:panelGrid columns="2" border="0">
                <h:commandButton value="Add attribute" action="#{categoryCTRL.addDefineCategoryAttribute}"/>
                <h:commandButton value="Remove attribute" action="#{categoryCTRL.removeDefineCategoryAttribute}"/>          
            </h:panelGrid>
        </h:form>
    </ui:define>

</ui:composition>
